#pragma once

#include "geometry.h"
#include "subdivision_util.h"

class Vertex {
private:
    Vector3d project(int iK) const;

    double getCurvature(int start) const;

    static Eigenstructure* eigenstructures;
public:
    int index;
    int sharpness;
    bool opt; //optimize this vertex?
    int N;
    vector<Edge*> edges;
    vector<Face*> faces;
    Vector3d pos;

    //pointer to the next vertex in the Catmull-Clark subdivision.
    Vertex* ccVertex;

    double gaussianCurvature;
    double meanCurvature;
    Vector3d uTangent, vTangent, normal;

    static void useEigenstructures(Eigenstructure* e);

    Vertex();

    Vertex(int index, const Vector3d& pos, int sharpness, bool opt);

    void setCCVertex(Vertex* v);
    void setCCLimitVertex(Vertex* v);

    //get edge on this vertex with the proper endpoints
    Edge* getEdge(int a, int b) const;

    void addEdge(Edge* edge);
    void addFace(Face* face);

    Vector3d derivative(int m, int n) const;

    void sort();
    void calculateCurvatures();

    void vertexGeometry(bool useMeanCurvature) const;
    void normalGeometry(double length) const;

    double approxArea() const;
    double approxLocalMeanCurvatureSq();

    double getMeanCurvature();
};
